package com.lixiaoyu.dao;

import com.lixiaoyu.entity.ExpressUser;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户 持久层
 */
public class UserDB {


    Map<Integer,ExpressUser> userMap = new HashMap();

    {
        ExpressUser user = new ExpressUser();
        user.setPussWord("123456");
        user.setPower(0);
        userMap.put(100,user);
        ExpressUser user1 = new ExpressUser();
        user1.setPussWord("123456");
        user1.setPower(1);
        userMap.put(200,user1);

    }



    public Map loginExpress(ExpressUser expressUser) {
        Map<Integer,String> map = new HashMap<>();

        for (Integer m: userMap.keySet()) {
            if(m == expressUser.getUserName()){
                if(userMap.get(m).getPussWord().equals(expressUser.getPussWord())){
                    if(userMap.get(m).getPower() == 0){
                        map.put(0,"登陆成功");
                        return map;
                    }
                    if(userMap.get(m).getPower() == 1){
                        map.put(1,"登陆成功");
                        return map;
                    }
                }else{
                        map.put(3,"密码不正确,请重新登陆！");
                        return map;
                }
            }
        }
        map.put(3,"用户名不正确,请重新登陆!");
        return map;
    }

    /**
     * 数据库 进行存储
     * @param expressUser
     * @return
     */
    public String registerUser(ExpressUser expressUser) {

        userMap.put(expressUser.getUserName(),expressUser);
        for (Integer m: userMap.keySet()) {
            System.out.println("用户名："+m);
            System.out.println("密码："+userMap.get(m));
            System.out.println("----------------------------");
        }
        return "注册成功";
    }
}
